package Relatorios;

import hibernate.dao.HibernateConnection;

import java.awt.EventQueue;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTable;
import javax.swing.border.EmptyBorder;

import skin.LookAndFeelSelector;

import com.toedter.calendar.JDateChooser;

import factory.FabricaDeFrame;

import javax.swing.JScrollPane;

public class FrmRelatorioEstoque extends JFrame {
	private JPanel contentPane;
	private JLabel lblSelecioneOCliente;
	private JScrollPane scrollPaneEstoque ;
	private JTable tbHistorico;
	private JComboBox cbTiposRelatorio;
	private JButton btnGerarRelatorio;
	private JSeparator separator;
	private JButton btnExcel;
	private JButton btnPdf;
	private CtrlRelatorio ctrl = new CtrlRelatorio();
	
	


	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					HibernateConnection.init();
					LookAndFeelSelector.lookAndFeelNimbus();
					FrmRelatorioEstoque frame = new FrmRelatorioEstoque();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	
	public FrmRelatorioEstoque() {
		setTitle("Relat\u00F3rio de Estoque");
		setIconImage(Toolkit.getDefaultToolkit().getImage("src/Repositorio/icon.png"));
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 543, 373);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		setLocationRelativeTo(null);
		contentPane.setLayout(null);
		
		lblSelecioneOCliente = new JLabel("Selecione o tipo de Relat\u00F3rio:");
		lblSelecioneOCliente.setBounds(6, 22, 187, 16);
		contentPane.add(lblSelecioneOCliente);
		
		cbTiposRelatorio = new JComboBox();
		cbTiposRelatorio.setBounds(177, 17, 222, 26);
		contentPane.add(cbTiposRelatorio);
	
		btnGerarRelatorio = new JButton("Gerar");
		btnGerarRelatorio.setBounds(411, 16, 90, 28);
		contentPane.add(btnGerarRelatorio);
		btnGerarRelatorio.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				ctrl.carregaTableEstoque(tbHistorico);
				
			}
		});
		
		separator = new JSeparator();
		separator.setBounds(6, 54, 529, 8);
		contentPane.add(separator);
		
		scrollPaneEstoque = new JScrollPane();
		scrollPaneEstoque.setBounds(63, 71, 408, 198);
		contentPane.add(scrollPaneEstoque);
		
		tbHistorico = new JTable();
		tbHistorico.setBounds(35, 73, 412, 198);
		scrollPaneEstoque.setViewportView(tbHistorico);
		
		btnExcel = new JButton();
		btnExcel.setToolTipText("Exporta para Excel");
		btnExcel.setIcon(new ImageIcon("src/Repositorio/btn_excel.png"));
		btnExcel.setBounds(349, 282, 50, 50);
		contentPane.add(btnExcel);
		btnExcel.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				ctrl.exportaExcelEstoque();
				
			}
		});
		
		btnPdf = new JButton("");
		btnPdf.setToolTipText("Exporta para PDF");
		btnPdf.setIcon(new ImageIcon("src/Repositorio/btn_pdf.png"));
		btnPdf.setBounds(421, 282,50, 50);
		contentPane.add(btnPdf);
		
		this.addWindowListener(new WindowAdapter() {
			
			public void windowOpened(WindowEvent e){
				ctrl.carregaCbEstoque(cbTiposRelatorio);
			}
		});
		
		
		
	}
}


